<template>
  <div class="pagination" v-if="showPagination">
    <el-pagination
      background
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page.sync="paginationInfo.currentPage"
      :page-size="paginationInfo.pageSize"
      :page-sizes="pageSizes"
      :total="paginationInfo.total"
      :layout="layout"
    ></el-pagination>
  </div>
</template>
<script>
/* eslint-disable */
import { scrollTo } from "./scrollTo";
export default {
  props: {
    pageSizes: {
      type: Array,
      default() {
        return [10, 15, 20, 25, 30];
      }
    },
    paginationInfo: {
      required: true,
      type: Object,
      default: {
        currentPage: 1,
        pageSize: 10,
        total: 0
      }
    },
    layout: {
      type: String,
      default() {
        return "total, sizes, prev, pager, next, jumper";
      }
    },
    autoScroll: {
      type: Boolean,
      default: true
    }
  },
  methods: {
    //点击页数
    handleSizeChange(val) {
      this.$set(this.paginationInfo, "pageSize", val);
      this.$emit("changePage", {});
      // console.log(`每页 ${val} 条`);
      if (this.autoScroll) {
        scrollTo(0, 800);
      }
    },
    handleCurrentChange(val) {
      // console.log(`当前页: ${val}`);
      this.$emit("changePage", { currentPage: val });
      if (this.autoScroll) {
        scrollTo(0, 100);
      }
    }
  },
  computed: {
    showPagination() {
      return this.paginationInfo.total == 0 ? false : true;
    }
  }
};
</script>
<style lang="less" scoped>
.pagination {
  padding-top: 30px;
}
</style>
